var express = require('express');
var bodyParser = require('body-parser')
var request = require('request');
var router = express.Router();
var article = require('../db_control/articleData_control')

const link = require('../db_control/link')
const conn = link.conn

router.get('/', function(req, res, next) {
	res.render('index', {
		title: 'Express'
	});
});



router.post('/postArticle', function(req, res, next) {
	article.add_data(req.body)
})

router.get('/getArticle', (req, res, next) => {
	var addSql = 'SELECT * FROM articledata';
	conn.query(addSql, (err, result) => {
		if (err) {
			reject(err)
		} else {
			e=JSON.parse(JSON.stringify(result))
			res.send(e)
		}
	})
})

module.exports = router;
